import { Column, Entity, Index } from 'typeorm';
import { DBEntity } from '../db.entity';
import { ObjectType, Field } from 'type-graphql';

@Entity('menu', { schema: 'vone' })
@Index('uk_name', ['name'], { unique: true })
@ObjectType()
export class Menu extends DBEntity {
  @Column('varchar', {
    nullable: false,
    unique: true,
    name: 'name',
  })
  @Field({ nullable: false, description: '菜单名,唯一标识' })
  name: string;

  @Column('varchar', {
    nullable: false,
    name: 'label',
  })
  @Field({ nullable: false, description: '显示的名称' })
  label: string;

  @Column('varchar', {
    nullable: true,
    name: 'icon',
  })
  @Field({ nullable: true, description: '图标code' })
  icon: string | null;

  @Column('varchar', {
    nullable: true,
    name: 'icon_theme',
  })
  @Field({ nullable: true, description: '图标风格' })
  iconTheme: string | null;

  @Column('varchar', {
    nullable: true,
    name: 'component',
  })
  component: string | null;

  @Column('bigint', {
    nullable: false,
    name: 'parent_id',
  })
  parentId: string;

  @Column('tinyint', {
    nullable: false,
    width: 1,
    default: () => '\'1\'',
    name: 'is_leaf',
  })
  isLeaf: boolean;

  @Field(type => [Menu], { nullable: true, description: '子菜单列表' })
  subMenu?: Menu[];
}
